#include "WindowHelper.h"
#include "../SDLtoolkit/widgets/PlayScenarioPanel.h"
#include "../SDLtoolkit/widgets/Label.h"
#include "../SDLtoolkit/widgets/LabelStatus.h"
#include "../SDLtoolkit/widgets/Textbox.h"
#include "../SDLtoolkit/widgets/RectangleBorder.h"
#include "../SDLtoolkit/widgets/Button.h"
#include "../SDLtoolkit/widgets/ItemList.h"
#include "../SDLtoolkit/widgets/ScrollItemList.h"
#include "../SDLtoolkit/widgets/listeners/ConnectButtonListener.h"
#include "../SDLtoolkit/widgets/listeners/CreateServerButtonListener.h"
#include "../SDLtoolkit/widgets/listeners/ExitButtonListener.h"
#include "../SDLtoolkit/widgets/listeners/TabClientButtonListener.h"
#include "../SDLtoolkit/widgets/listeners/TabServerButtonListener.h"

Window* WindowHelper::playSceneWindow(SpaceBattleInterface* game, bool esAdmin) {
	Logger::debug("WindowHelper", "playWindow", "Abriendo el escenario ");

	Window* playWindow = new Window(play,Color::NEGRO,game->getWidth(),game->getHeight());

	PlayScenarioPanel* panel = new PlayScenarioPanel(0, 0, playWindow, game, esAdmin);

	playWindow->setScenarioContainer(panel);

	return playWindow;
}

Window* WindowHelper::connectGameWindow() {

	Window* connectGameWindow = new Window(CONNECT,Color::GRIS,GAME_MENU_WIDTH,GAME_MENU_HEIGHT);

	Listener* tabClientButtonListener = new TabClientButtonListener();
	Button* tabClientButton = new Button(" ","client", 0, 0,connectGameWindow, tabClientButtonListener);
	connectGameWindow->add(tabClientButton);

	Listener* tabServerButtonListener = new TabServerButtonListener();
	Button* tabServerButton = new Button(" ","servidor",80, 0,connectGameWindow, tabServerButtonListener);
	connectGameWindow->add(tabServerButton);

	// Solapa Cliente

	Label* label = new Label("Host:",connectGameWindow, 80, 60);
	connectGameWindow->add(label);

	Textbox* hostTextBox = new Textbox("localhost",120, 40, connectGameWindow);
	connectGameWindow->add(hostTextBox);

	Label* labelPuerto = new Label("Puerto:",connectGameWindow, 80, 110);
	connectGameWindow->add(labelPuerto);

	Textbox* portTextBox = new Textbox("9999",120, 90, connectGameWindow);
	connectGameWindow->add(portTextBox);

	Label* label2 = new Label("Jugador:",connectGameWindow, 80, 160);
	connectGameWindow->add(label2);

	Textbox* userNameTextBox = new Textbox("Tester",120, 140, connectGameWindow);
	connectGameWindow->add(userNameTextBox);

	Button* quitButton = new Button("Salir", Color::AMARILLO,100,60,50, 220,connectGameWindow, new ExitButtonListener());
	connectGameWindow->add(quitButton);

	Listener* connectButtonListener = new ConnectButtonListener(userNameTextBox, hostTextBox, portTextBox);
	Button* enterButton = new Button("Conectar", Color::AMARILLO,100,60, 200, 220,connectGameWindow, connectButtonListener);
	connectGameWindow->add(enterButton);

	LabelStatus* labelStatus = new LabelStatus("Esperando Conectar",connectGameWindow, 0, GAME_MENU_HEIGHT-20);
	connectGameWindow->add(labelStatus);

	RectangleBorder* border = new RectangleBorder(0,30,GAME_MENU_WIDTH,GAME_MENU_HEIGHT,connectGameWindow);
	connectGameWindow->add(border);

	return connectGameWindow;
}

Window* WindowHelper::createGameWindow() {

	Window* createGameWindow = new Window(CREATE,Color::GRIS,GAME_MENU_WIDTH,GAME_MENU_HEIGHT);

	Listener* tabClientButtonListener = new TabClientButtonListener();
	Button* tabClientButton = new Button(" ","client", 0, 0,createGameWindow, tabClientButtonListener);
	createGameWindow->add(tabClientButton);

	Listener* tabServerButtonListener = new TabServerButtonListener();
	Button* tabServerButton = new Button(" ","servidor",80, 0,createGameWindow, tabServerButtonListener);
	createGameWindow->add(tabServerButton);

	// Solapa Servidor
	ScrollItemList* scenariosScrollList = new ScrollItemList(SCENARIOS_FILE,40,40,createGameWindow);
	createGameWindow->add(scenariosScrollList);

	Label* labelServerPuerto = new Label("Puerto:", createGameWindow, 80, 170);
	createGameWindow->add(labelServerPuerto);

	Textbox* serverPortTextBox = new Textbox("9999",120, 150, createGameWindow);
	createGameWindow->add(serverPortTextBox);

	Button* quitButton2 = new Button("Salir", Color::AMARILLO,100,60,50, 220,createGameWindow, new ExitButtonListener());
	createGameWindow->add(quitButton2);

	Listener* createServerButtonListener = new CreateServerButtonListener(serverPortTextBox,scenariosScrollList);
	Button* createButton = new Button("Iniciar", Color::AZUL, 100, 60, 200, 220,createGameWindow, createServerButtonListener);
	createGameWindow->add(createButton);

	LabelStatus* labelStatus = new LabelStatus("Esperando Iniciar",createGameWindow, 0, GAME_MENU_HEIGHT-20);
	createGameWindow->add(labelStatus);

	RectangleBorder* border = new RectangleBorder(0,30,GAME_MENU_WIDTH,GAME_MENU_HEIGHT,createGameWindow);
	createGameWindow->add(border);

	return createGameWindow;
}


Window* WindowHelper::exitWindow() {
	Window* exitWindow = new Window(EXIT,Color::BLANCO,GAME_MENU_WIDTH,GAME_MENU_HEIGHT);

	Label* label = new Label("Saliendo ...",exitWindow, 20, 50);
	exitWindow->add(label);

	return exitWindow;
}
